package com.yxhl.zoume.core.specialcar.presenter;

import android.content.Context;
import android.text.TextUtils;

import com.yxhl.zoume.common.presenter.BasePresenter;
import com.yxhl.zoume.common.presenter.IPresenter;
import com.yxhl.zoume.common.ui.view.BaseView;
import com.yxhl.zoume.core.specialcar.view.SpecialCarScheduleView;
import com.yxhl.zoume.data.http.rest.param.specialcar.CancelOrderParam;
import com.yxhl.zoume.data.http.rest.response.specialcar.CancelOrderResponse;
import com.yxhl.zoume.domain.interactor.ZMSubscriber;
import com.yxhl.zoume.domain.interactor.car.specialcar.CancelSpecialCarOrderUseCase;

import javax.inject.Inject;

/**
 * Created by sugarya on 16/4/25.
 * 取消快车订单
 */
public class CancelSpecialCarPresenter extends BasePresenter implements IPresenter {

    private static final String TAG = "SpecialSchedulePresenter";

    @Inject
    CancelSpecialCarOrderUseCase mCancelSpecialCarOrderUseCase;

    private SpecialCarScheduleView mSpecialCarScheduleView;

    @Inject
    public CancelSpecialCarPresenter(Context context) {
        super(context);
    }


    public void cancelSpecialCarOrder(String orderId) {
        CancelOrderParam param = new CancelOrderParam(
                getMobile(),
                getToken(),
                orderId
        );
        mCancelSpecialCarOrderUseCase.execute(param,new ZMSubscriber<CancelOrderResponse>() {
                    @Override
                    public void onCompleted() {
                        super.onCompleted();
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }

                    @Override
                    public void onNext(CancelOrderResponse cancelOrderResponse) {
                        super.onNext(cancelOrderResponse);
                        if (cancelOrderResponse != null) {
                            boolean isSucc = cancelOrderResponse.isSucc();
                            if (isSucc) {
                                mSpecialCarScheduleView.renderDataOnSuccess();
                            } else {
                                String resultMessage = cancelOrderResponse.getResultMessage();
                                if (!TextUtils.isEmpty(resultMessage)) {
                                    mSpecialCarScheduleView.renderDataOnFailure(resultMessage);
                                }
                            }
                        }
                    }
                });
    }


    @Override
    public void attachView(BaseView view) {
        if (view instanceof SpecialCarScheduleView) {
            mSpecialCarScheduleView = (SpecialCarScheduleView) view;
        }
    }

    @Override
    public void onResume() {

    }

    @Override
    public void onPause() {

    }

    @Override
    public void onDestroy() {

    }
}
